package homeWork05.Test4;

public class Student implements Comparable{

    //    设计一个类Student，该类包括姓名、学号和成绩。
    //    设计一个方法，按照成绩从高到低的顺序输出姓名、学号和成绩信息
    String name;
    int sid;
    int score;

    public Student(){}

    public Student(String name,int sid,int score){
        this.score = score;
        this.name = name;
        this.sid = sid;
    }

    @Override
    public int compareTo(Object o) {
        Student s = (Student)o;
        return s.score - this.score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", sid=" + sid +
                ", score=" + score +
                '}';
    }

    public void print(Student[] students){
        for(int i = 0; i < students.length;i++){
            for(int j = 0;j < students.length - i -1;j++){
                if(students[j].score < students[j + 1].score){
                    Student temp = students[j];
                    students[j] = students[j + 1];
                    students[j + 1] = temp;
                }
            }
        }
        for(int i = 0; i < students.length;i++){
            System.out.print(students[i]+" ");
        }
    }


}
